#! /usr/bin/perl -w
#

# Author			: WangYongdong
# Email				: jjjarod@gmail.com
# Description	: Convert binary .264 file to text format
# Usage				: bin2hex.pl input_file output_file                
# Copyright (C) 2009 WangYongdong

$srcfile = $ARGV[0];
$destfile = $ARGV[1];

open INF, "$srcfile" or die "Can't open $srcfile for reading!\n";
open OUTF, ">$destfile" or die "Can't open $destfile for writing!\n";
binmode(INF);

$s = '';
$i = 0;
while (!eof(INF))
{
	if ($i >= 2)
	{
		printf OUTF "%s\n", $s;
		$s = '';
		$i = 0;
	}
	else
	{
		$i++;
		$s .= sprintf("%02X",ord(getc(INF)));
	}
}
###if last line of BINFILE is less than 16 byte
if ($i < 2)
{
	printf OUTF "%s",$s;
}
close (INF); 
close (OUTF);